(function(window, undefined) {
    var storage = window.storage || {};
    
    storage.getItem = function(key) {
        return storage.local.enabled() ? storage.local.getItem(key) : storage.cookie.getItem(key);
    };
    storage.setItem = function(key, value, days) {
        if (days) 
            storage.cookie.setItem(key, value, days);
        else
            storage.local.enabled() ? storage.local.setItem(key, value) : storage.cookie.setItem(key, value);
    };
    storage.removeItem = function(key, value) {
        if (storage.local.enabled()) storage.local.removeItem(key);
        storage.cookie.removeItem(key);
    };
    storage.clear = function(key, value) {
        if (storage.local.enabled()) storage.local.clear();
        storage.cookie.clear();
    };
    storage.keys = function() {
        return storage.cookie.keys().concat(storage.cookie.keys() ? storage.local.keys() : new Array());
    }
})(window);

try { window.storage.getItem(null); } catch (e) {}
try { window.storage.setItem(null, null); } catch (e) {}
